home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / basic / mildred / lha / pixelexplosion.lha / 2DPixelExplosion.asc next >
Text File  |  1999-01-25  |  4KB  |  116 lines

  1.  
  2. ;Pixel Explosion Mildred Library Example.
  3. ;
  4. ;Programmed by : Mikkel Loekke, aka. FlameDuck.
  5. ;
  6. ;Please read the README file.
  7.  
  8. ;                  __ _
  9. ;Modified by Sami Naatanen (25.01.1999)
  10. ; Just made it faster and more "realistic"
  11. ; Can now do easily 4000 pixels and 060 with 10000 stars is still
  12. ; super smooth! In fact 15000 stars runs quite smooth
  13. ; (some jerking at the beginning).
  14.  
  15. WBStartup
  16. NoCli
  17.  
  18. degrad.q = Pi/180
  19.  
  20. NEWTYPE .point
  21.   x.q
  22.   y.q
  23.   anglx.q
  24.   angly.q
  25. End NEWTYPE
  26.  
  27. #numpnts=4000                       ; Change this for more or less points.
  28.  
  29. Dim pnt.point (#numpnts)
  30.  
  31. DEFTYPE.l
  32.  
  33. MCPU Processor                      ; Tell Mildred which CPU it should use.
  34. Mc2pCPUmode Processor               ; Tell Mildred which CPU it should use for c2p.
  35.  
  36. MReserveBitmaps 1                   ; Tell Mildred that we're going to use 1 chunky bitmap.
  37. MReservec2pWindows 1                ; Tell it we only need one c2p display.
  38. MReserveShapes 1                    ; Tell Mildred that we need a shape aswell.
  39.  
  40. InitPalette 0,256                   ; Setup a grayscale palette.
  41. For t.l=0To 255
  42.   AGAPalRGB 0,t,t,t,t
  43. Next
  44.  
  45. .initgraphics
  46. MBitmap 0,320,256                   ; This will contain our chunky buffer.
  47.  
  48. Mc2pWindow 0,320,256                ; Setup structures for c2p conversions.
  49.  
  50. *pbb.l=AllocMem(320*256,$10002)     ; Get some free CHIP memory
  51. If *pbb.l                           ; and if we succeed
  52.   CludgeBitMap 0,320,256,8,*pbb     ; make it a planar bitmap.
  53. Else End
  54. EndIf
  55.  
  56. Dim scrtaglst.TagItem(7)            ; All this stuff sets up our
  57. scrtaglst(0)\ti_Tag = #SA_Left      ; Taglist for the screen we
  58. scrtaglst(0)\ti_Data = 0            ; want.
  59. scrtaglst(1)\ti_Tag = #SA_Depth
  60. scrtaglst(1)\ti_Data = 8
  61. scrtaglst(2)\ti_Tag = #SA_Width
  62. scrtaglst(2)\ti_Data = 320
  63. scrtaglst(3)\ti_Tag = #SA_Height
  64. scrtaglst(3)\ti_Data = 256
  65. scrtaglst(4)\ti_Tag = #SA_BitMap
  66. scrtaglst(4)\ti_Data = Addr BitMap (0)
  67. scrtaglst(5)\ti_Tag = #SA_ShowTitle
  68. scrtaglst(5)\ti_Data = 0
  69. scrtaglst(6)\ti_Tag = #SA_Draggable
  70. scrtaglst(6)\ti_Data = 0
  71. scrtaglst(7)\ti_Tag = #TAG_END      ; The most important tag of them all.
  72.  
  73. ScreenTags 0,"MildredDEMO",&scrtaglst(0) ; Open our intuition screen.
  74.  
  75. ShowPalette 0                       ; Attach our palette to the screen.
  76.  
  77.  
  78. Dim cin.q(359),kos.q(359)
  79.  
  80. For t.l=0 To 359
  81.   cin(t)=Sin(degrad*t)
  82.   kos(t)=Cos(degrad*t)
  83. Next t
  84. .goagain                            ; A Label that tells us where to go
  85.                                     ; to reset all our variables
  86. For t.l=0To #numpnts
  87.   pnt(t)\x=160
  88.   pnt(t)\y=128
  89.   r.w=Rnd(359)
  90.   v.q=Rnd(Rnd(4.4)+3)+Rnd(1.6)
  91.   pnt(t)\anglx=cin(r)*v
  92.   pnt(t)\angly=kos(r)*v
  93. Next
  94.  
  95. phase.w=0
  96. Repeat                              ; Repeat our mainloop ....
  97.   Mc2p *pbb                         ; Convert our chunky buffer to
  98.                                     ; our planar bitmap.
  99.   MCls                              ; Clear our chunky buffer
  100.   pntskip.w=0
  101.   For t=0 To #numpnts               ; Boring math part. It's really
  102.                                     ; not as complicated as it looks
  103.     If (pnt(t)\y>0 AND pnt(t)\y<256) AND (pnt(t)\x>0 AND pnt(t)\x<320)
  104.       MPlot pnt(t)\x,pnt(t)\y,255-phase
  105.       pnt(t)\x-pnt(t)\anglx
  106.       pnt(t)\y-pnt(t)\angly
  107.     Else
  108.       pntskip+1
  109.     EndIf
  110.   Next
  111.   phase+2:If phase=256 Then pntskip=#numpnts
  112. Until RawStatus($45) OR pntskip=#numpnts  ; .... Until we press Escape, or the fade is complete.
  113. If pntskip=#numpnts Then Goto goagain     ; If the fade completed, reset variables, and go again.
  114. End                                 ; End our nice program.
  115.  
  116.